home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Moscow ML 1.31 / source code / mosml / src / mosmllib / List.sig < prev    next >
Encoding:
Text File  |  1996-07-03  |  3.8 KB  |  106 lines  |  [TEXT/R*ch]

  1. (* List -- SML Standard Library *)
  2.  
  3. exception Empty  (* Subscript and Size *)
  4.  
  5. val null       : 'a list -> bool
  6. val hd         : 'a list -> 'a                        (* Empty     *)
  7. val tl         : 'a list -> 'a list                   (* Empty     *)
  8. val last       : 'a list -> 'a                        (* Empty     *)
  9.  
  10. val nth        : 'a list * int -> 'a                   (* Subscript *)
  11. val take       : 'a list * int -> 'a list          (* Subscript *)
  12. val drop       : 'a list * int -> 'a list          (* Subscript *)
  13.  
  14. val length     : 'a list -> int 
  15.  
  16. val rev        : 'a list -> 'a list 
  17.  
  18. val @          : 'a list * 'a list -> 'a list
  19. val concat     : 'a list list -> 'a list
  20. val revAppend  : 'a list * 'a list -> 'a list
  21.  
  22. val app        : ('a -> unit) -> 'a list -> unit
  23. val map        : ('a -> 'b) -> 'a list -> 'b list
  24. val mapPartial : ('a -> 'b option) -> 'a list -> 'b list
  25.  
  26. val find       : ('a -> bool) -> 'a list -> 'a option
  27. val filter     : ('a -> bool) -> 'a list -> 'a list
  28. val partition  : ('a -> bool ) -> 'a list -> ('a list * 'a list)
  29.  
  30. val foldr      : ('a * 'b -> 'b) -> 'b -> 'a list -> 'b
  31. val foldl      : ('a * 'b -> 'b) -> 'b -> 'a list -> 'b
  32.  
  33. val exists     : ('a -> bool) -> 'a list -> bool
  34. val all        : ('a -> bool) -> 'a list -> bool
  35.  
  36. val tabulate   : int * (int -> 'a) -> 'a list         (* Size      *)
  37.  
  38. (* [null xs] is true iff xs is nil.
  39.  
  40.    [hd xs] returns the first element of xs.  Raises Empty if xs is nil.
  41.  
  42.    [tl xs] returns all but the first element of xs.  
  43.    Raises Empty if xs is nil.
  44.  
  45.    [last xs] returns the last element of xs.  Raises Empty if xs is nil.
  46.  
  47.    [nth(xs, i)] returns the i'th element of xs, counting from 0.
  48.    Raises Subscript if i<0 or i>=length xs.
  49.  
  50.    [take(xs, i)] returns the first i elements of xs.  Raises Subscript
  51.    if i<0 or i>length xs.
  52.  
  53.    [drop(xs, i)] returns what is left after dropping the first i
  54.    elements of xs.  Raises Subscript if i<0 or i>length xs.  
  55.    It holds that take(xs, i) @ drop(xs, i) = xs when 0 <= i <= length xs.
  56.  
  57.    [length xs] returns the number of elements in xs.
  58.  
  59.    [rev xs] returns the list of xs's elements, reversed.
  60.  
  61.    [xs @ ys] returns the list which is the concatenation of xs and ys.
  62.  
  63.    [concat xss] returns the list which is the concatenation of all the
  64.    lists in xss.
  65.  
  66.    [app f xs] applies f to the elements of xs, from left to right.
  67.  
  68.    [map f xs] applies f to each element x of xs, from left to
  69.    right, and returns the list of f's results.
  70.  
  71.    [mapPartial f xs] applies f to each element x of xs, from left
  72.    to right, and returns the list of those y's for which f(x)
  73.    evaluated to SOME y.
  74.  
  75.    [find p xs] applies f to each element x of xs, from left to
  76.    right until p(x) evaluates to true; returns SOME x if such an x
  77.    exists otherwise NONE.
  78.  
  79.    [filter p xs] applies p to each element x of xs, from left to
  80.    right, and returns the sublist of those x for which p(x) evaluated
  81.    to true.
  82.  
  83.    [partition p xs] applies p to each element x of xs, from left
  84.    to right, and returns a pair (pos, neg) where pos is the sublist
  85.    of those x for which p(x) evaluated to true, and neg is the sublist of
  86.    those for which p(x) evaluated to false.
  87.  
  88.    [foldr op% e xs] evaluates x1 % (x2 % ( ... % (x(n-1) % (xn % e)) ... ))
  89.    where xs = [x1, x2, ..., x(n-1), xn], and % is taken to be infixed.
  90.  
  91.    [foldl op% e xs] evaluates xn % (x(n-1) % ( ... % (x2 % (x1 % e))))
  92.    where xs = [x1, x2, ..., x(n-1), xn], and % is taken to be infixed.
  93.  
  94.    [exists p xs] applies p to each element x of xs, from left to
  95.    right until p(x) evaluates to true; returns true if such an x
  96.    exists, otherwise false.
  97.  
  98.    [all p xs] applies p to each element x of xs, from left to
  99.    right until p(x) evaluates to false; returns false if such an x
  100.    exists, otherwise true.
  101.  
  102.    [tabulate(n, f)] returns a list of length n whose elements are
  103.    f(0), f(1), ..., f(n-1), created from left to right.  Raises Size
  104.    if n<0.
  105. *)
  106.